import Vue from 'vue'
import Vuex from 'vuex'

import {
  bbsFansQuery,
  bbsFansDelete,
  bbsFansAdd,
  bbsFansUpdate,
  bbsFansQueryById,
  bbsFansMyInfo,
  bbsFansQueryMyFans,
  bbsFansQueryMyFollow,
  bbsFansCancel,
} from '@/api/bbs/bbsFans'

Vue.use(Vuex)

const state = {}

const getters = {}

const actions = {
  //评论增删改查
  async queryBbsFans({ commit }, listQuery) {
    let res = await bbsFansQuery({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async queryBbsFansById({ commit }, id) {
    let res = await bbsFansQueryById(id)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async delBbsFans({ commit }, row) {
    let res = await bbsFansDelete(row.id)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async addBbsFans({ commit }, data) {
    let res = await bbsFansAdd(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async updateBbsFans({ commit }, data) {
    let res = await bbsFansUpdate(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async myInfoBbsFans({ commit }, id) {
    let res = await bbsFansMyInfo(id)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async queryMyFansBbsFans({ commit }, listQuery) {
    let res = await bbsFansQueryMyFans({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async queryMyFollowBbsFans({ commit }, listQuery) {
    let res = await bbsFansQueryMyFollow({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async cancelBbsFans({ commit }, id) {
    let res = await bbsFansCancel(id)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
}

const mutations = {}

export default {
  state,
  getters,
  actions,
  mutations,
}
